﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BusinessLayer.Logic.UserLogic;

namespace BusinessLayer.Logic
{

        public sealed class DictionaryManager
        {
           private static volatile DictionaryManager instance;
           private static object syncRoot = new Object();
           private Dictionary<String, Dictionary<String, String>> langDictionaries;


           public static DictionaryManager Instance
           {
              get 
              {
                 if (instance == null) 
                 {
                    lock (syncRoot) 
                    {
                       if (instance == null)
                           instance = new DictionaryManager();
                    }
                 }

                 return instance;
              }
           }
           private DictionaryManager()
           {
               langDictionaries = new Dictionary<string, Dictionary<string, string>>();
           }

           public void addDictionary(Dictionary<String, String> dict, String language)
           {
               lock (this)
               {
                   if (langDictionaries.ContainsKey(language))
                       langDictionaries[language] = dict;
                   else
                       langDictionaries.Add(language, dict);
               }
           }
           public String getString(String language,String key)
           {
               lock (this)
               {
                   return langDictionaries[language][key];
               }
           }
           public Dictionary<String,String> getLanguage(String language)
           {
               lock (this)
               {
                   Dictionary<String,String> ret=null;
                   langDictionaries.TryGetValue(language, out ret);
                   return ret;
               }
           }


           
        }
}
